package blockchain.entity.block;

import com.xiaoleilu.hutool.crypto.digest.DigestUtil;

/**
 * 区块结构
 *
 * @Author: 李浩然
 * @Date: 2020/12/23 10:25 下午
 */
public class Block {
    /**
     * 区块头
     */
    private BlockHeader blockHeader;
    /**
     * 区块体
     */
    private BlockBody blockBody;
    /**
     * 区块Hash
     */
    private String blockHash;

    /**
     * 计算SHA256Hex
     *
     * @return
     */
    public String getBlockHash() {
        return DigestUtil.sha256Hex(blockHeader.toString() + blockBody.toString());
    }

    public void setBlockHash(String blockHash) {
        this.blockHash = blockHash;
    }

    public BlockHeader getBlockHeader() {
        return blockHeader;
    }

    public void setBlockHeader(BlockHeader blockHeader) {
        this.blockHeader = blockHeader;
    }

    public BlockBody getBlockBody() {
        return blockBody;
    }

    public void setBlockBody(BlockBody blockBody) {
        this.blockBody = blockBody;
    }
}
